package org.gokulam.cgfw.core;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

public class Configurator {
	
	 
	private static final String INPUT_DIR = "input.dir";
	private static final String TEMPLATE_PATH = "template.dir";
	private static final String fileName = "resources/setup.properties"; 
	protected Properties config;
	
	public Configurator() {
		config = new Properties();
	}
	
	public void load() {
		try {
			config.load(new FileInputStream(fileName));
		} catch (FileNotFoundException e) {
			System.err.println(Messages.getString("Configurator.config.file.not.found") + fileName); //$NON-NLS-1$
			e.printStackTrace();
		} catch (IOException e) {
			System.err.println(Messages.getString("Configurator.failed.to.read.config.file") + fileName); //$NON-NLS-1$
			e.printStackTrace();
		}
	}
	
	public String getParameter(String key) {
		String value = config.getProperty(key);
		if (value == null){
			throw new RuntimeException(fileName + Messages.getString("Configurator.property.not.defined") + key); //$NON-NLS-1$
		}
		return value;
	}
	
	public String getTemplateDir() {
		return getParameter(TEMPLATE_PATH);
	}
	
	public String getInputDir() {
		return this.getParameter(INPUT_DIR);
	}

}
